package com.linwen.excise.leetcode;

/**
 * @ClassName _860柠檬水找零
 * @Description TODO
 * @Author zero
 * @DATE 2024/10/7 2:44 PM
 * @Version 1.0
 */
public class _860柠檬水找零 {
    public static void main(String[] args) {
        _860柠檬水找零 inst = new _860柠檬水找零();
        int[] bills = {5, 5, 5, 10, 20};
        System.out.println(inst.lemonadeChange(bills));
    }

    public boolean lemonadeChange(int[] bills) {
        int[] change = new int[2];
        for (int bill : bills) {
            if(bill==5){
                change[0]++;
            }else if(bill==10){
                if(change[0]==0){
                    return false;
                }else {
                    change[0]--;
                    change[1]++;
                }
            }else if(bill==20){
                if(change[0]==0){
                    return false;
                }
                if(change[1]>0){
                    change[1]--;
                    change[0]--;
                }else {
                    if(change[0]>=3){
                        change[0] -= 3;
                    }else {
                        return false;
                    }
                }
            }
        }
        return true;
    }
}
